import { defineConfig } from 'vite';
import uni from '@dcloudio/vite-plugin-uni';
import eslintPlugin from 'vite-plugin-eslint';
import AutoImport from 'unplugin-auto-import/vite';
import Components from '@uni-helper/vite-plugin-uni-components';
import { WotResolver } from '@uni-helper/vite-plugin-uni-components/resolvers';
import uniTailwind from '@uni-helper/vite-plugin-uni-tailwind';
import TransformPages from 'uni-read-pages-vite';
import tailwindcss from 'tailwindcss';
import path from 'path';
export default defineConfig({
	resolve: {
		alias: {
			'@': path.resolve(__dirname, './src'),
		},
	},
	plugins: [
		AutoImport({
			//自动按需导入
			imports: [
				'vue',
				'vue-router',
				'pinia',
				{
					from: 'uni-mini-router',
					imports: ['createRouter', 'useRouter', 'useRoute'],
				},
			],
			eslintrc: {
				enabled: false, // 1、改为true用于生成eslint配置。2、生成后改回false，避免重复生成消耗
				filepath: './.eslintrc-auto-import.json', // 指定自动导入函数 eslint 规则的文件
			},
			dts: './src/types/auto-imports.d.ts',
		}),
		eslintPlugin({
			include: ['src/**/*.ts', 'src/**/*.vue', 'src/*.ts', 'src/*.vue'],
		}),
		Components({
			resolvers: [WotResolver()],
			dts: './src/types/components.d.d.ts',
		}),
		uni(),
		uniTailwind(),
	],
	css: {
		preprocessorOptions: {
			scss: {
				additionalData: `@import "@/styles/index.scss";`,
			},
		},
		postcss: {
			plugins: [tailwindcss()],
		},
	},
	define: {
		ROUTES: new TransformPages().routes, // 注入路由表
	},
});
